package com.fz.common;


import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;


/**
 * 返回数据模型
 * @author
 *
 */

@Data
@SuppressWarnings("unchecked")
public class ResponseEntity<T> implements Serializable {

	/**
	 * 
	 */

	/**
	 * 状态，
	 */
	@ApiModelProperty(value = "返回状态码")
	private int status;

	/**
	 * 信息
	 */
	@ApiModelProperty(value = "返回消息")
	private String message;

	/**
	 * 数据
	 */
	@ApiModelProperty(value = "返回数据")
	private T data;
	@ApiModelProperty(value = "返回时间戳")
	private long date;
	
	public ResponseEntity(){
		this.date = new Date().getTime();
	}


	/**
	 * 构建ResponseResult
	 * 
	 * @param status
	 *            响应状态吗
	 * @param message
	 *            响应消息
	 * @return ResponseResult
	 */
	public static <T> ResponseEntity build(int status, String message) {
		ResponseEntity<T> result = new ResponseEntity<T>();
		result.setStatus(status);
		result.setMessage(message);
		return result;
	}
	
	public static <T> ResponseEntity build(int status, String message,T t) {
		ResponseEntity result = new ResponseEntity();
		result.setStatus(status);
		result.setData(t);
		result.setMessage(message);
		return result;
	}


	public static <T> ResponseEntity buildError(String msg) {
		ResponseEntity<T> result = new ResponseEntity<T>();
		result.setStatus(StatusCode.SERVER_ERROR);
		result.setMessage(msg);
		return result;
	}

	/**
	 * 构建ResponseResult
	 *
	 * @param data
	 *            响应状态吗
	 * @return ResponseResult
	 */
	public static <T> ResponseEntity buildSuccess(T data) {
		ResponseEntity<T> result = new ResponseEntity<T>();
		result.setStatus(StatusCode.OK);
		result.setData(data);
		return result;
	}

	public static <T> ResponseEntity buildSuccess(){
		ResponseEntity<T> result = new ResponseEntity<T>();
		result.setStatus(StatusCode.OK);
		result.setData(null);
		return result;
	}




	public static <T> ResponseEntity build(ResultCode resultCode){
		ResponseEntity<T> result = new ResponseEntity<T>();
		result.setStatus(resultCode.getResultCode());
		result.setMessage(resultCode.getMessage());
		return result;
	}
}
